package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.xcity.game.achievement.Achievement;
import com.xcity.game.achievement.Achievement.State;
import com.xcity.game.achievement.AchievementTemplate;
import com.xcity.game.common.ItemResponse;
import com.xcity.game.item.ItemInfo;

import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@PomeloMessage(type = Message.Type.RESPONSE)
public class AchievementRewardResponse extends Response {

	private int id; // !!! 这id是成就类型，不是成就id !!!
	private String achievesName;
	private String desc;
	private String img;
	private int gold;
	private int stone;
	private List<ItemResponse> items; // 奖励物品
//	private int completeValue; // 达成目标需求值
	private boolean isHas; // 是否达成目标
	private boolean isReceived; // 是否领取奖励
	
	public AchievementRewardResponse(int serial, Achievement ref) {
		super(serial);
		AchievementTemplate template = ref.getTemplate();
		this.id = template.getGroup().ordinal(); // 成就类型
		this.achievesName = template.getName();
		this.desc = template.getDesc();
		this.img = template.getIcon();
		this.gold = template.getGold();
		this.stone = template.getStone();
		if (template.getRewardItems() != null) {
			ItemInfo[] refItems = template.getRewardItems();
			items = new ArrayList<ItemResponse>(refItems.length);
			for (ItemInfo refItem : refItems) {
				items.add(new ItemResponse(refItem));
			}
		} else {
			items = Collections.emptyList();
		}
		this.isHas = ref.getState() != State.INITED;
		this.isReceived = ref.getState() == State.REWARDED;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getAchievesName() {
		return achievesName;
	}

	public void setAchievesName(String achievesName) {
		this.achievesName = achievesName;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public String getImg() {
		return img;
	}

	public void setImg(String img) {
		this.img = img;
	}

	public int getGold() {
		return gold;
	}

	public void setGold(int gold) {
		this.gold = gold;
	}

	public int getStone() {
		return stone;
	}

	public void setStone(int stone) {
		this.stone = stone;
	}

//	public int getCompleteValue() {
//		return completeValue;
//	}
//
//	public void setCompleteValue(int completeValue) {
//		this.completeValue = completeValue;
//	}

	public List<ItemResponse> getItems() {
		return items;
	}

	public void setItems(List<ItemResponse> items) {
		this.items = items;
	}

	public boolean isIsHas() {
		return isHas;
	}

	public void setIsHas(boolean isHas) {
		this.isHas = isHas;
	}

	public boolean isIsReceived() {
		return isReceived;
	}

	public void setIsReceived(boolean isReceived) {
		this.isReceived = isReceived;
	}

}
